package crazy.crack;

import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;

public class HashTable
{
	public static void main(String[] args)
	{
		System.out.println(isUniqueChars("abcc"));
	}
	
	public HashMap<Integer, Student> buildMap(Student[] students)
	{
		HashMap<Integer, Student> map = new HashMap<Integer, Student>();
		for (Student s : students)
		{
			map.put(s.getId(), s);
		}
		return map;
	}
	
	public ArrayList<String> merge(String[] words, String[] more)
	{
		ArrayList<String> sentence = new ArrayList<String>();
		for (String w : words)
		{
			sentence.add(w);
		}
		
		for (String m : more)
		{
			sentence.add(m);
		}
		return sentence;
	}
	
	public String makeSentence(String[] words)
	{
		StringBuffer sb = new StringBuffer();
		for (String w : words)
		{
			sb.append(w);
		}
		return sb.toString();
	}
	
	
	public static boolean isUniqueChars2(String str)
	{
		boolean[] char_set = new boolean[256];

		
		for (int i = 0; i < str.length(); i++)
		{
			int val = str.charAt(i);
			if (char_set[val])
			{
				return false;
			}
			char_set[val] = true;
		}
		return true;
	}
	
	public static boolean isUniqueChars(String str)
	{
		int checker = 0;
		for (int i = 0; i < str.length(); i++)
		{
			int val = str.charAt(i)-'a';
			System.out.println(val +"");
			if ((checker&(1 <<val))>0)
			{
				return false;
			}
			checker = checker | (1 << val);
		}
		return true;
	}
	
	public static void writeLog(String mess)
	{
		PrintStream ps = null;
		try
		{
			ps = new PrintStream(new FileOutputStream("c:\\log.txt"));
			ps.println(mess);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		finally
		{
			try
			{
				if (ps != null)
					ps.close();
			}
			catch (Exception e2)
			{
				e2.printStackTrace();
			}
		}
	}
}

class Student
{
	private int id;
	
	public int getId()
	{
		return id;
	}
	
	public void setId(int id)
	{
		this.id = id;
	}
}
